package com.wfuhui.modules.store.api;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.wfuhui.common.annotation.AuthIgnore;
import com.wfuhui.common.utils.R;
import com.wfuhui.modules.store.entity.StoreEntity;
import com.wfuhui.modules.store.service.StoreService;

@RestController
@RequestMapping("/api/store")
public class ApiStoreController {

	@Autowired
	private StoreService storeService;
	
    @AuthIgnore
    @GetMapping("list")
    public R list(String longitude, String latitude){
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("longitude", longitude);
    	params.put("latitude", latitude);
    	params.put("status", 2);
    	List<StoreEntity> storeList = storeService.queryNearby(params);
        return R.ok().put("storeList", storeList);
    }
    
    @PostMapping("apply")
    public R apply(@RequestBody StoreEntity store, @RequestAttribute("userId") Long userId) {
    	store.setCreateTime(new Date());
    	store.setUserId(userId);
    	storeService.save(store);
    	return R.ok();
    }

    @AuthIgnore
    @GetMapping("info")
    public R info(Integer id){
        StoreEntity store = storeService.queryObject(id);
        return R.ok().put("store", store);
    }
    
}
